import pymysql
import os
db_host = "172.0.0.3"
db_user = "root"
db_password = "rootroot"
db_name = "mytest"

conn = pymysql.connect(host=db_host, user=db_user, passwd=db_password)
cur = conn.cursor()
cur.execute('show databases')

check_exists = False
for one_item in cur.fetchall():
    if one_item[0] == db_name:
        check_exists = True
        break

if not check_exists:
    cur.execute('create database mytest')
    os.system('source ~/.bashrc && python3 manage.py makemigrations && python3 manage.py migrate && python3 manage.py runserver 127.0.0.1:8000')
else:
    os.system('source ~/.bashrc && python3 manage.py runserver 127.0.0.1:8000')